/*
 * @Author: your name
 * @Date: 2021-03-24 22:18:12
 * @LastEditTime: 2021-04-03 23:04:00
 * @LastEditors: Please set LastEditors
 * @Description: 实时动态
 * @FilePath: \jianfa-api\routes\admin\state.js
 */
const express = require('express');
const router = express.Router();
const Result = require('../../models/result');
const { addListService, addWebUrlService, getListService, getUrlService, delListService, delUrlService, addTowListService, delTowListService, getTowListService } = require('../../service/stateService');


// get二级父菜单
router.get('/get_tow_list', async (req, res, next) => {
    const { status, results } = await getTowListService(req.body)
    if (status) {
        new Result(results, 'get成功').success(res)
    } else {
        new Result({}, 'get失败').fail(res)
    }
})

//获取实时动态列表
router.post('/get_list', async (req, res, next) => {
    const { status, results } = await getListService(req.body)
    if (status) {
        new Result(results, '查询成功').success(res)
    } else {
        new Result({}, '查询失败').fail(res)
    }
})
//更具id获取实时动态url
router.post('/get_url', async (req, res, next) => {
    const { status, results } = await getUrlService(req.body)
    let data = { results, total: global.all_let.TOTAL }
    global.all_let.TOTAL != null ? null : delete data.total
    if (status) {
        new Result(data, '查询成功').success(res)
    } else {
        new Result({}, '查询失败').fail(res)
    }
})

module.exports = router;